
	** Append South Africa waves
	
		use "$dir/data/saf_w1_individual.dta", clear
		ren w1_* *
		gen wave="w1"
		tempfile data
		save `data', replace
		
		qui foreach wave in w2 w3 w4 w5 {
			use "$dir/data/saf_`wave'_individual.dta", clear
			ren `wave'_* *
			gen wave="`wave'"
			append using `data'
			save `data', replace
		}
			
	** Age groups
		replace age=. if age<0
		gen age_group5=floor(age/5)*5
		gen age_group10=floor(age/10)*10
		
		replace age_group5=80 if age_group5>80 & !missing(age_group5)
		replace age_group10=80 if age_group10>80 & !missing(age_group10)
		
	** Any work
		*egen work_any=rowmax(work_outsideHH work_agHH work_bizHH)
	
	** Lives alone
		gen lives_alone=(hh_size==1)
		
	** Urban
		*ren geo_urban urban

	** Disability
		gen disability=(																	 	 ///
			diff_seei==1 | 																	 	 ///
			diff_hear==1 | 																	     ///
			diff_walk_clim==1 | 															     ///
			diff_self_care==1 																	 ///
			)
		replace disability=. if (														         ///
			missing(diff_seei) &																 ///
			missing(diff_hear) & 														     	 ///
			missing(diff_walk_clim) & 														 	 ///
			missing(diff_self_care)      													     ///
			)	
		
		save "$dir/data/saf.dta", replace
		
	** Double checks: summarize important variables by wave to check for consistency
	
		foreach var of varlist hh_size-lives_alone {
			tab wave, sum(`var')
		}
		
		** FIXME: primary occupation variable very different in waves 2 and 3 (because there's no "exists" variable)
		